//
//  PersonalController.m
//  HaoHaiSpell
//
//  Created by 郭健 on 16/6/14.
//  Copyright © 2016年 海城. All rights reserved.
//

#import "PersonalController.h"
#import "LoginController.h"
#import "GJInfoCell.h"
#import "GJNormalCell.h"
#import "NormalCellModel.h"
#import "ShippingAddressController.h"

#import "MyGroupController.h"
#import "IndianaRecordController.h"
#import "CollectionController.h"
#import "CouponsController.h"
<<<<<<< HEAD
=======
#import "WalletViewController.h"
#import "JoinViewController.h"
#import "ProblemViewController.h"



#import "ComprehensiveController.h"
>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d

#import "GJGroup.h"
#import "GJInfoCellModel.h"
//<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@interface PersonalController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong) UITableView *tableview;
@property(nonatomic,strong) UIImageView *loginView;
@property(nonatomic,strong) UIButton *loginBtn;
@property(nonatomic,strong) UILabel *noticeLabel;
@property(nonatomic,strong) UILabel *nickname;
@property(nonatomic,assign) BOOL isLogin;


//网络请求返回的字典数据
@property(nonatomic,strong) NSDictionary *dictData;

@property(nonatomic,strong) NSMutableArray *normalArray;
@end

@implementation PersonalController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
}


-(void)addLoginWithNoToken{

    [self addUpNoToken];
    [self addGroup];
    [self setAddCell];
    [self.loginBtn setTitle:@"登录" forState:UIControlStateNormal];
//    self.noticeLabel.text = @"您还没登录";
}


//隐藏导航栏
-(void)viewWillAppear:(BOOL)animated{

    self.navigationController.navigationBarHidden = YES;
    
    self.tabBarController.tabBar.hidden = NO;
    
    [self addLoginWithNoToken];
}

//上面登录页面
-(void)addUpNoToken{

    self.loginView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"headerImage"] highlightedImage:[UIImage imageNamed:@"headerImage"]];
    
    self.loginView.frame = CGRectMake(0, 0, self.view.bounds.size.width, 150);
    self.loginView.userInteractionEnabled = YES;
    
    //loginBtn
    self.loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.loginBtn.center = CGPointMake(_loginView.center.x, _loginView.center.y);
    self.loginBtn.bounds = CGRectMake(0, 0, 80, 25);
    self.loginBtn.backgroundColor = [UIColor clearColor];
    self.loginBtn.layer.masksToBounds = YES;
    self.loginBtn.layer.cornerRadius = 10;
    self.loginBtn.layer.borderWidth = 1;
    self.loginBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.loginBtn addTarget:self action:@selector(loginPage) forControlEvents:UIControlEventTouchUpInside];
    
    //loginLabel
    self.noticeLabel = [[UILabel alloc]init];
    self.noticeLabel.center = CGPointMake(_loginView.center.x, _loginView.center.y);
    self.noticeLabel.bounds = CGRectMake(0, 0, 200, 25);
    self.noticeLabel.textAlignment=NSTextAlignmentCenter;
    self.noticeLabel.textColor=[UIColor whiteColor];
    
    self.noticeLabel.font=[UIFont systemFontOfSize:15];
    //添加到self.view中
    [self.loginView addSubview:self.loginBtn];
    [self.loginView addSubview:self.noticeLabel];
    [self.view addSubview:self.loginView];
    
}


//添加组
-(void)addGroup{

    self.normalArray = [NSMutableArray array];

    //分组
    GJGroup *group = [[GJGroup alloc]init];
    GJInfoCellModel *info1 = [[GJInfoCellModel alloc]initWithImageName:@"daifukuan" title:@"待付款" selector:@selector(payAction)];
    GJInfoCellModel *info2 = [[GJInfoCellModel alloc]initWithImageName:@"daifahuo" title:@"待发货" selector:@selector(deliveryAction)];
    GJInfoCellModel *info3 = [[GJInfoCellModel alloc]initWithImageName:@"daishouhuo" title:@"待收货" selector:@selector(goodsAction)];
    GJInfoCellModel *info4 = [[GJInfoCellModel alloc]initWithImageName:@"daipingjia" title:@"待评价" selector:@selector(evaluationAction)];
    
    group.items = @[info1,info2,info3,info4];
    
    
    //第一组
    GJGroup *group_1 = [[GJGroup alloc]init];
    NSString *verifystatusdesc = @"未认证";
    
    if (self.isLogin) {
        verifystatusdesc = self.dictData[@"verifystatusdesc"];
    }
    
    
//    NormalCellModel *one = [[NormalCellModel alloc]initWithImage:@"" titleOne:@"实名认证" titleTwo:verifystatusdesc];
    NormalCellModel *two = [[NormalCellModel alloc]initWithImage:@"wodetuan" titleOne:@"我的团" titleTwo:nil];
    NormalCellModel *three = [[NormalCellModel alloc]initWithImage:@"duobaojilu" titleOne:@"夺宝记录" titleTwo:nil];
    NormalCellModel *four = [[NormalCellModel alloc]initWithImage:@"shoucang" titleOne:@"我的收藏" titleTwo:nil];
    NormalCellModel *five = [[NormalCellModel alloc]initWithImage:@"youhuijuan" titleOne:@"我的优惠券" titleTwo:nil];
    NormalCellModel *goods = [[NormalCellModel alloc]initWithImage:@"shouhuodizhi" titleOne:@"收货地址" titleTwo:nil];
    NormalCellModel *wallet = [[NormalCellModel alloc]initWithImage:@"wodeqianbao" titleOne:@"我的钱包" titleTwo:nil];
    NormalCellModel *distribution = [[NormalCellModel alloc]initWithImage:@"fenxiao" titleOne:@"我的分销" titleTwo:nil];
    NormalCellModel *Application = [[NormalCellModel alloc]initWithImage:@"shenqingruzhu" titleOne:@"申请入驻" titleTwo:nil];
    NormalCellModel *problem = [[NormalCellModel alloc]initWithImage:@"changjianwenti" titleOne:@"常见问题" titleTwo:nil];
    group_1.items = @[two,three,four,five,goods,wallet,distribution,Application,problem];
    
    //第二组
    GJGroup *group_2 = [[GJGroup alloc]init];
    NormalCellModel *Setup = [[NormalCellModel alloc]initWithImage:@"shezhi" titleOne:@"设置" titleTwo:nil];
    group_2.items = @[Setup];
    
    //第三组
    GJGroup *group_3 =[[GJGroup alloc]init];
    NormalCellModel *exit = [[NormalCellModel alloc]initWithImage:@"" titleOne:@"退出账号" titleTwo:nil];
    group_3.items = @[exit];
    
    
    [self.normalArray addObject:group];
    [self.normalArray addObject:group_1];
    [self.normalArray addObject:group_2];
    if (self.isLogin) {
        [self.normalArray addObject:group_3];
    }
}

-(void)setAddCell{

    //cell 界面
    CGFloat x = 0;
    CGFloat y = 150;
    CGFloat width = self.view.bounds.size.width;
    CGFloat height = self.view.bounds.size.height - 150 - 49;
    
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(x, y, width, height) style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    
    self.tableview = tableView;
    [self.view addSubview:tableView];
}

-(void)loginPage{

    LoginController *LoginVC = [[LoginController alloc]init];
    LoginVC.hidesBottomBarWhenPushed = YES;
    LoginVC.title = @"登录";
    self.navigationController.navigationBarHidden = NO;
    [self.navigationController pushViewController:LoginVC animated:YES];
    
}


//调整状态栏颜色
-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

#pragma mark -- 按钮的回调方法
-(void)payAction{

<<<<<<< HEAD
    NSLog(@"代付款");
=======
    self.navigationController.navigationBarHidden = NO;
    self.tabBarController.tabBar.hidden = YES;
    
    ComprehensiveController *comprehensiveVC = [[ComprehensiveController alloc]init];
    [self.navigationController pushViewController:comprehensiveVC animated:YES];
>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d
}

-(void)deliveryAction{

<<<<<<< HEAD
=======
    self.navigationController.navigationBarHidden = NO;
    self.tabBarController.tabBar.hidden = YES;

    ComprehensiveController *comprehensiveVC_1 = [[ComprehensiveController alloc]init];
    [self.navigationController pushViewController:comprehensiveVC_1 animated:YES];
    
>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d
    NSLog(@"代发货");
}

-(void)goodsAction{

    NSLog(@"待收货");
}

-(void)evaluationAction{

    NSLog(@"待评价");
}



#pragma mark -- UITableView的代理方法
//实现tableview的代理方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //每组有多少行
    if (section==0) {
        return 1;
    }
    GJGroup *temp=self.normalArray[section];
    return temp.items.count;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.normalArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0) {
        GJInfoCell *cell = [GJInfoCell initWithTableView:tableView];
        
        //取出模型
        GJGroup *group = self.normalArray[0];
        cell.dataArray = group.items;
        return cell;
    }else{
    
        GJNormalCell *cell = [GJNormalCell initWithTableView:tableView];
        
        //取出模型
        GJGroup *group = self.normalArray[indexPath.section];
        NormalCellModel *data = group.items[indexPath.row];
        cell.imageView.image = [UIImage imageNamed:data.imageName];
        cell.textLabel.text = data.titleOne;
        cell.detailTextLabel.text=data.titleTwo;
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        return cell;
        
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==0) {
        return 0.1;
    }
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        return 70;
    }
    return 44;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NSLog(@"第%ld个cell",indexPath.row);
    
<<<<<<< HEAD
    if (indexPath.row == 4) {
       
        self.navigationController.navigationBarHidden = NO;
        self.tabBarController.tabBar.hidden = YES;
        
        ShippingAddressController *shippingAddressVC  = [[ShippingAddressController alloc]init];
        
        [self.navigationController pushViewController:shippingAddressVC animated:YES];
        
    }else if (indexPath.row == 0){
        
         self.navigationController.navigationBarHidden = NO;
        self.tabBarController.tabBar.hidden = YES;
    
        MyGroupController *myGroupVC = [[MyGroupController alloc]init];
        [self.navigationController pushViewController:myGroupVC animated:YES];
    }else if(indexPath.row == 1){
    
        self.navigationController.navigationBarHidden = NO;
        self.tabBarController.tabBar.hidden = YES;
        
        IndianaRecordController *indianRecordVC = [[IndianaRecordController alloc]init];
        [self.navigationController pushViewController:indianRecordVC animated:YES];
    
    }else if (indexPath.row == 2){
    
        self.navigationController.navigationBarHidden = NO;
        self.tabBarController.tabBar.hidden = YES;
    
        CollectionController *collectionVC = [[CollectionController alloc]init];
        [self.navigationController pushViewController:collectionVC animated:YES];
    
    }else if(indexPath.row == 3){
    
        self.navigationController.navigationBarHidden = NO;
        self.tabBarController.tabBar.hidden = YES;
        
        CouponsController *couponsVC = [[CouponsController alloc]init];
        [self.navigationController pushViewController:couponsVC animated:YES];
    
    }
    
=======
    self.navigationController.navigationBarHidden = NO;
    self.tabBarController.tabBar.hidden = YES;
    
    if (indexPath.row == 4) {
               
        ShippingAddressController *shippingAddressVC  = [[ShippingAddressController alloc]init];
        [self.navigationController pushViewController:shippingAddressVC animated:YES];
    }else if (indexPath.row == 0){
        
        MyGroupController *myGroupVC = [[MyGroupController alloc]init];
        [self.navigationController pushViewController:myGroupVC animated:YES];
    }else if(indexPath.row == 1){

        IndianaRecordController *indianRecordVC = [[IndianaRecordController alloc]init];
        [self.navigationController pushViewController:indianRecordVC animated:YES];
    }else if (indexPath.row == 2){
        
        CollectionController *collectionVC = [[CollectionController alloc]init];
        [self.navigationController pushViewController:collectionVC animated:YES];
    }else if(indexPath.row == 3){
    
        CouponsController *couponsVC = [[CouponsController alloc]init];
        [self.navigationController pushViewController:couponsVC animated:YES];
    }else if (indexPath.row == 5){
    
        WalletViewController *walletVC = [[WalletViewController alloc]init];
        [self.navigationController pushViewController:walletVC animated:YES];
    }else if(indexPath.row == 7){
    
        JoinViewController *joinVC = [[JoinViewController alloc]init];
        [self.navigationController pushViewController:joinVC animated:YES];
    }else if(indexPath.row == 8){
    
        ProblemViewController *problemVC = [[ProblemViewController alloc]init];
        [self.navigationController pushViewController:problemVC animated:YES];
    }
>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d
    
}

























- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
